package com.dongdong.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdong.data.DataResult;
import com.dongdong.data.ResponseStatusEnum;
import com.dongdong.pojo.TbContent;
import com.dongdong.service.ContentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Deacription TODO
 * @Author Lenovo
 * @Date 2020/12/16 11:48
 * @Version 1.0
 **/
@Controller
@RequestMapping("contentController")
public class ContentController {

    private static final Logger logger = LoggerFactory.getLogger(ContentController.class);

    @Reference
    private ContentService contentService;

    //轮播图
    @RequestMapping("getCarousel")
    @ResponseBody
    public DataResult getCarousel(){
        try {
            List<TbContent> contentList = contentService.getCarousel();
            return DataResult.response(ResponseStatusEnum.SUCCESS).setData(contentList);
        }catch (Exception e){
            logger.error("轮播图查询错误");
            return DataResult.response(ResponseStatusEnum.INTERNAL_SERVER_ERROR);
        }
    }

    //今日推荐
    @RequestMapping("getCommend")
    @ResponseBody
    public DataResult getCommend(){
        try {
            List<TbContent> contentList = contentService.getCommend();
            return DataResult.response(ResponseStatusEnum.SUCCESS).setData(contentList);
        }catch (Exception e){
            logger.error("今日推荐查询错误");
            return DataResult.response(ResponseStatusEnum.INTERNAL_SERVER_ERROR);
        }
    }

    //猜你喜欢
    @RequestMapping("getLike")
    @ResponseBody
    public DataResult getLike(){
        try {
            List<TbContent> contentList = contentService.getLike();
            return DataResult.response(ResponseStatusEnum.SUCCESS).setData(contentList);
        }catch (Exception e){
            logger.error("猜你喜欢查询错误");
            return DataResult.response(ResponseStatusEnum.INTERNAL_SERVER_ERROR);
        }
    }

    //有趣区
    @RequestMapping("getAmusing")
    @ResponseBody
    public DataResult getAmusing(){
        try {
            List<TbContent> contentList = contentService.getAmusing();
            return DataResult.response(ResponseStatusEnum.SUCCESS).setData(contentList);
        }catch (Exception e){
            logger.error("有趣区查询错误");
            return DataResult.response(ResponseStatusEnum.INTERNAL_SERVER_ERROR);
        }
    }

    //楼层
    @RequestMapping("getFloorCarousels")
    @ResponseBody
    public DataResult getFloorCarousels(){
        try {
            List<TbContent> contentList = contentService.getFloorCarousels();
            return DataResult.response(ResponseStatusEnum.SUCCESS).setData(contentList);
        }catch (Exception e){
            logger.error("有趣区查询错误");
            return DataResult.response(ResponseStatusEnum.INTERNAL_SERVER_ERROR);
        }
    }

}

